winbrew_engines\windows\msix/
install.rs

1//! MSIX installation implementation.
2//!
3//! This is a thin adapter around the Windows App Installer APIs exposed by
4//! `crate::windows_dep::packages::msix_install`. It does not unpack files or manage a
5//! portable install tree; it only records the MSIX receipt metadata WinBrew
6//! needs later for removal.
7
8use anyhow::{Context, Result};
9use std::fs;
10use std::path::Path;
11
12use crate::models::install::engine::{
13    EngineInstallReceipt, EngineKind, EngineMetadata, InstallScope,
14};
15
16use crate::windows_dep::packages::msix_install;
17
18/// Install an MSIX package and return the receipt data WinBrew needs later.
19///
20/// The function calls into Windows to register the package, creates the target
21/// install directory so the install record has a concrete path, and returns an
22/// `EngineInstallReceipt` with `EngineKind::Msix` plus `EngineMetadata::Msix`.
23pub(crate) fn install(
24    download_path: &Path,
25    install_dir: &Path,
26    package_name: &str,
27) -> Result<EngineInstallReceipt> {
28    let package_full_name =
29        msix_install(download_path, package_name).context("msix install failed")?;
30
31    fs::create_dir_all(install_dir)
32        .with_context(|| format!("failed to create {}", install_dir.display()))?;
33
34    let engine_metadata = Some(EngineMetadata::msix(
35        package_full_name,
36        InstallScope::Installed,
37    ));
38
39    Ok(EngineInstallReceipt::new(
40        EngineKind::Msix,
41        install_dir.to_string_lossy().into_owned(),
42        engine_metadata,
43    ))
44}